<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- jQuery的支持 -->
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.1.1/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <script>
        window.onload = function () {
            $.ajax({
                url: "merchant/all",
                type: "get",
                dataType: "json",
                success: function (res) {
                    console.log(res);
                if (res.code === 200) {
                    let data_val = res.data
                    for (let i = 0; i < data_val.length; i++) {
                        let status_val = data_val[i].mstate;
                        if (status_val == 1){
                            status_val = "已通过";
                        }else if(status_val == 2){
                            status_val = "未通过";
                        }else {
                            status_val = "审核中";
                        }

                        $("<tr><td>"+(data_val[i].mid)+"</td><td>"+data_val[i].mrealName+"</td><td>"+data_val[i].mcontact+"</td><td>"+data_val[i].mphone+"</td><td>"+data_val[i].memail+"</td><td>"+data_val[i].maddress+"</td><td>"+ (data_val[i].merchantType == 1 ? '个人' : '企业') +"</td><td>"+data_val[i].midCard+"</td><td>"+status_val+"</td><td>"+data_val[i].create_time+"</td><td><button class='btn btn-success btn-sm' onclick='examine("+data_val[i].mid+")'>通过</button>&nbsp;&nbsp;<button onclick='unexamine("+data_val[i].mid+")' class='btn btn-danger btn-sm'>拒绝</button></td></tr>").appendTo($("#tb"));


                        // document.getElementById("tb").append(tr);
                        }

                }
                },
                complete:function (res){
                    console.log(res)
                }
            })
    }
    function examine(obj) {
        var anw = window.confirm("确定审核通过" + obj + "?");
        if (anw) {
            $.ajax({
                url: "merchant/status/" + obj,
                type: "get",
                dataType: "json",
                // data: {
                //     mid: obj
                // },
                success: function (res) {
                    console.log(res);
                    if (res.code == 200) {
                        alert("审核通过成功");
                        window.location.reload();
                    }else {
                        alert("审核失败,权限不足");
                    }
                },
                complete: function (res) {
                    console.log(res)
                }
            })
        }else {
            return;
        }
    }
    function unexamine(obj) {
        var anw = window.confirm("确定拒绝" + obj + "?");
        if (anw) {
            $.ajax({
                url: "merchant/unstatus/" + obj,
                type: "get",
                dataType: "json",
                // data: {
                //     mid: obj
                // },
                success: function (res) {
                    console.log(res);
                    if (res.code == 200) {
                       alert("拒绝成功");
                    }else {
                        alert("拒绝失败,权限不足")
                        return ;
                    }
                }
            })
        }
    }

    function searchData(obj) {
            console.log('1111111111111', obj)
            var search_val = document.getElementById("search").value;
            $.ajax({
                url: "merchant/search?mrealname=" + search_val,
                type: "get",
                dataType: "json",
                success: function (res) {
                    console.log(res);
                if (res.code === 200) {
                    $("#tb").empty();
                    let data_val = res.data
                    for (let i = 0; i < data_val.length; i++) {
                        let status_val = data_val[i].mstate;
                        if (status_val == 1){
                            status_val = "已通过";
                        }else if(status_val == 2){
                            status_val = "未通过";
                        }else {
                            status_val = "审核中";
                        }

                        $("<tr><td>"+(data_val[i].mid)+"</td><td>"+data_val[i].mrealName+"</td><td>"+data_val[i].mcontact+"</td><td>"+data_val[i].mphone+"</td><td>"+data_val[i].memail+"</td><td>"+data_val[i].maddress+"</td><td>"+ (data_val[i].merchantType == 1 ? '个人' : '企业') +"</td><td>"+data_val[i].midCard+"</td><td>"+status_val+"</td><td>"+data_val[i].create_time+"</td><td><button class='btn btn-success btn-sm' onclick='examine("+data_val[i].mid+")'>通过</button>&nbsp;&nbsp;<button onclick='unexamine("+data_val[i].mid+")' class='btn btn-danger btn-sm'>拒绝</button></td></tr>").appendTo($("#tb"));

                    }
                }
                }
            })
}
    </script>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Brand</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <!--<ul class="nav navbar-nav">-->
            <!--    <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>-->
            <!--    <li><a href="#">Link</a></li>-->
            <!--    &lt;!&ndash;<li class="dropdown">&ndash;&gt;-->
            <!--    &lt;!&ndash;    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>&ndash;&gt;-->
            <!--    &lt;!&ndash;    <ul class="dropdown-menu">&ndash;&gt;-->
            <!--    &lt;!&ndash;        <li><a href="#">Action</a></li>&ndash;&gt;-->
            <!--    &lt;!&ndash;        <li><a href="#">Another action</a></li>&ndash;&gt;-->
            <!--    &lt;!&ndash;        <li><a href="#">Something else here</a></li>&ndash;&gt;-->
            <!--    &lt;!&ndash;        <li role="separator" class="divider"></li>&ndash;&gt;-->
            <!--    &lt;!&ndash;        <li><a href="#">Separated link</a></li>&ndash;&gt;-->
            <!--    &lt;!&ndash;        <li role="separator" class="divider"></li>&ndash;&gt;-->
            <!--    &lt;!&ndash;        <li><a href="#">One more separated link</a></li>&ndash;&gt;-->
            <!--    &lt;!&ndash;    </ul>&ndash;&gt;-->
            <!--    &lt;!&ndash;</li>&ndash;&gt;-->
            <!--</ul>-->
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search" id="search" oninput="searchData(this.value)">
                </div>
                <!--<button type="submit" class="btn btn-default">Submit</button>-->
            </form>
            <!--<ul class="nav navbar-nav navbar-right">-->
            <!--    <li><a href="#">Link</a></li>-->
            <!--    <li class="dropdown">-->
            <!--        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>-->
            <!--        <ul class="dropdown-menu">-->
            <!--            <li><a href="#">Action</a></li>-->
            <!--            <li><a href="#">Another action</a></li>-->
            <!--            <li><a href="#">Something else here</a></li>-->
            <!--            <li role="separator" class="divider"></li>-->
            <!--            <li><a href="#">Separated link</a></li>-->
            <!--        </ul>-->
            <!--    </li>-->
            <!--</ul>-->
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

<table class="table table-striped table-hover table-bordered">
    <thead>
        <th>#</th>
        <!--<th>用户名</th>-->
        <!--<th>密码</th>-->
        <th>真实姓名</th>
        <th>联系人</th>
        <th>电话</th>
        <th>邮箱</th>
        <th>地址</th>

        <!--<th>证件</th>-->
        <th>商家类型</th>
        <th>证件号</th>
        <th>状态</th>
        <th>审核时间</th>
        <th>操作</th>
    </thead>
    <tbody id="tb">

    </tbody>
    <tfoot>
        <tr>
            <td colspan="10" style="text-align: center">显示分页信息</td>
        </tr>
    </tfoot>
</table>
</body>
</html>